package com.shanwen.shopping.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.classic.common.MultipleStatusView;
import com.classic.core.log.Logger;
import com.classic.core.utils.DataUtil;
import com.classic.core.utils.NetworkUtil;
import com.shanwen.shopping.R;
import com.shanwen.shopping.adapter.GoodsAdapter;
import com.shanwen.shopping.consts.Consts;
import com.shanwen.shopping.entity.EBannerInfo;
import com.shanwen.shopping.entity.GoodsClassify;
import com.shanwen.shopping.entity.GoodsDetail;
import com.shanwen.shopping.entity.GoodsInfo;
import com.shanwen.shopping.entity.GoodsPage;
import com.shanwen.shopping.http.ActionHelp;
import com.shanwen.shopping.http.ListCallback;
import com.shanwen.shopping.http.ObjectCallback;
import com.shanwen.shopping.utils.MenuAnimationUtil;
import com.shanwen.shopping.view.SuperSwipeRefreshLayout;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bingoogolapple.bgabanner.BGABanner;

public class GoodsHomeActivity extends AppBaseActivity implements BGABanner.Adapter<ImageView, EBannerInfo>,
        BGABanner.Delegate<ImageView, EBannerInfo> {

    @BindView(R.id.goods_home_multiple_status_view)
    MultipleStatusView multipleStatusView;
    @BindView(R.id.BgaBanner)
    BGABanner BgaBanner;
    //    @BindView(R.id.goods_home_classify_lv)
//    ListView mClassifyLv;
//    @BindView(R.id.goods_home_hot_lv)
//    ListView mHotLv;
//    @BindView(R.id.goods_home_search_et)
//    EditText mSearch;
//    @BindView(R.id.goods_home_search_iv)
//    ImageView ivSearch;
//    @BindView(R.id.goods_home_back_top)
//    ImageView ivBackTop;
    @BindView(R.id.ivFushi)
    ImageView ivFushi;
    @BindView(R.id.ivBaiHuo)
    ImageView ivBaiHuo;
    @BindView(R.id.ivOther)
    ImageView ivOther;
    @BindView(R.id.ivSort)
    ImageView ivSort;
    @BindView(R.id.ivGoodsAll)
    ImageView ivGoodsAll;

    @BindView(R.id.ivGoodsBack)
    ImageView ivGoodsBack;
    @BindView(R.id.ivGoodsChart)
    ImageView ivGoodsChart;
    @BindView(R.id.ivGoodsTop)
    ImageView ivGoodsTop;

    private SuperSwipeRefreshLayout mRefreshLayout;
    private GridView mContentGv;
//    private ClassifyAdapter classifyAdapter;
    private GoodsAdapter contentAdapter;

    private long currClassifyId;
    private boolean hasSearch;
    private MenuAnimationUtil animationUtil;
    private List<ImageView> ivs = new ArrayList<>();
    private long GOODS_ALL = -100;//为了复用之前的逻辑，修改之后，所有商品的分类id人为设置为-100
    private List<EBannerInfo> banners = new ArrayList<EBannerInfo>();
    private GoodsInfo bannerGoodsInfo = null;

    //四个分类是固定的，但是现在当某一分类下面没有商品数据时，后台不会在分类列表返回这一分类，导致四个固定的分类
    //与分类列表不能一一对应，顺序出错，所以定义该变量，为不存在的分类设置固定的id=-10，保持一一对应，由于现在id=-10
    //这个分类没有返回数据，所以处理起来比较简单，若id=-10，接口会报错，可以在判断当前分类id的地方对-10单独处理，return，不进入
    //下面调用接口的逻辑
    private final long NO_CLASSIFY = -10;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_goods_home;
    }

    @Override
    public void onBackClick() {
//        NewMainActivity.isCleanCart = true;//设置可清除购物车
        super.onBackClick();
    }

    @Override
    public void initView() {
        super.initView();
        ivs.add(ivFushi);
        ivs.add(ivBaiHuo);
        ivs.add(ivOther);
        ivs.add(ivGoodsAll);
        animationUtil = new MenuAnimationUtil(ivs);
        setTitle("会见超市");
        setBackEnabled(true);
        setShoppingCartEnabled(false);
//        multipleStatusView.showLoading();
        multipleStatusView.setOnRetryClickListener(onRetryClickListener);
        initContentView(multipleStatusView);
        initLoadingView();

        BgaBanner.setAdapter(this);
        BgaBanner.setDelegate(this);
//        mClassifyLv.setOnItemClickListener(new ClassifyItemClick());
//        mHotLv.setOnItemClickListener(new HotItemClick());
//        ivSearch.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                hasSearch = true;
//                searchGoods();
//            }
//        });
//        mSearch.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//                if (s.length() == 0) {
//                    hasSearch = false;
//                    initContentView(multipleStatusView);
//                    multipleStatusView.showContent();
//                    searchResult = null;
//                    cacheData.remove(currClassifyId);
//                    getGoodsByClassifyId(currClassifyId);
//                }
//            }
//        });
    }

//    @OnClick(R.id.goods_home_back_top)
//    public void onBackTopClick() {
//        if (mContentGv == null) return;
//        mContentGv.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                mContentGv.setSelection(0);
//            }
//        }, 100);
//    }

    @OnClick({R.id.ivFushi, R.id.ivBaiHuo, R.id.ivOther, R.id.ivSort, R.id.ivGoodsAll, R.id.ivGoodsBack, R.id.ivGoodsTop, R.id.ivGoodsChart})
    public void menuClick(View v) {
        switch (v.getId()) {
            case R.id.ivFushi:
                clickMenuBtn(ivs.indexOf(v));
                break;
            case R.id.ivBaiHuo:
                clickMenuBtn(ivs.indexOf(v));
                break;
            case R.id.ivOther:
                clickMenuBtn(ivs.indexOf(v));
                break;
            case R.id.ivSort:
                Boolean isShowing = (Boolean) ivSort.getTag();
                if (null == isShowing || isShowing == false) {
                    ivSort.setTag(true);
                    animationUtil.showMenu();
                } else {
                    ivSort.setTag(false);
                    animationUtil.closeMenu();
                }
                break;

            case R.id.ivGoodsAll:
                currClassifyId = GOODS_ALL;
                clickMenuBtn(ivs.indexOf(v));
                break;
            case R.id.ivGoodsBack:
                finish();
                break;
            case R.id.ivGoodsTop:
                if (mContentGv == null) return;
                mContentGv.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mContentGv.setSelection(0);
                    }
                }, 100);
                break;
            case R.id.ivGoodsChart:
//                startActivity(activity, ShoppingCartActivity.class);
                break;
        }
    }

    private void clickMenuBtn(int position) {
        if (ivs.get(position) == ivGoodsAll) {
            if (cacheData.containsKey(currClassifyId)) {
                refreshAdapter(currClassifyId);
            } else {
//                getHotGoods();
            }
        } else {
            if (goodsClassifies.size() == 0) {
                ivSort.setTag(false);
                animationUtil.closeMenu();
                return;
            }
            currClassifyId = goodsClassifies.get(position).getItemId();
//            if (currClassifyId==NO_CLASSIFY){
//                return
//            }
            if (cacheData.containsKey(currClassifyId)) {
                refreshAdapter(currClassifyId);
            } else {
                getGoodsByClassifyId(currClassifyId);
            }
        }
        animationUtil.closeMenu();
        ivSort.setTag(false);
    }

    private void initLoadingView() {
        if (NetworkUtil.isNetworkAvailable(activity)) {
            getClassifyList();
//            getHotGoods();
//            getBanner();
        } else {
            multipleStatusView.showNoNetwork();
        }
    }

    private void initContentView(View parentView) {
        mRefreshLayout = (SuperSwipeRefreshLayout) parentView.findViewById(R.id.content_view);
        mRefreshLayout.setHeaderView(createHeaderView());
        mRefreshLayout.setFooterView(createFooterView());
        mContentGv = (GridView) parentView.findViewById(R.id.goods_home_content_gv);
        mContentGv.setOnItemClickListener(new ContentItemClick());
        mRefreshLayout.setOnPushLoadMoreListener(new SuperSwipeRefreshLayout.OnPushLoadMoreListener() {
            @Override
            public void onLoadMore() {
                footerTextView.setText("正在加载...");
                footerImageView.setVisibility(View.GONE);
                footerProgressBar.setVisibility(View.VISIBLE);
                if (currClassifyId != GOODS_ALL) {
                    getGoodsByClassifyId(currClassifyId);
                } else {
//                    getHotGoods();
                }
            }

            @Override
            public void onPushDistance(int distance) {

            }

            @Override
            public void onPushEnable(boolean enable) {
                footerTextView.setText(enable ? "松开加载" : "上拉加载");
                footerImageView.setVisibility(View.VISIBLE);
                footerImageView.setRotation(enable ? 0 : 180);
            }
        });
        mRefreshLayout.setOnPullRefreshListener(new SuperSwipeRefreshLayout.OnPullRefreshListener() {
            @Override
            public void onRefresh() {
                textView.setText("正在刷新");
                imageView.setVisibility(View.GONE);
                progressBar.setVisibility(View.VISIBLE);
                cacheData.remove(currClassifyId);
                if (currClassifyId == GOODS_ALL) {
//                    getHotGoods();
                } else {
                    getGoodsByClassifyId(currClassifyId);
                }
            }

            @Override
            public void onPullDistance(int distance) {

            }

            @Override
            public void onPullEnable(boolean enable) {
                textView.setText(enable ? "松开刷新" : "下拉刷新");
                imageView.setVisibility(View.VISIBLE);
                imageView.setRotation(enable ? 180 : 0);
            }
        });

        contentAdapter = new GoodsAdapter(activity, R.layout.goods_item, new ArrayList<GoodsInfo>());
        mContentGv.setAdapter(contentAdapter);
    }

    private void finishRefreshOrLoadMore() {
        if (null != mRefreshLayout) {
            footerImageView.setVisibility(View.VISIBLE);
            footerProgressBar.setVisibility(View.GONE);
            progressBar.setVisibility(View.GONE);
            mRefreshLayout.setLoadMore(false);
            mRefreshLayout.setRefreshing(false);
        }
    }

    private List<GoodsClassify> goodsClassifies = new ArrayList<>();

    /**
     * 获取分类列表
     */
    private void getClassifyList() {
//        if (!DataUtil.isEmpty(goodsClassifies)) return;
        ActionHelp.qryGoodsItems(activity,
                new ListCallback<GoodsClassify>() {
                    @Override
                    public void onSuccess(List<GoodsClassify> response) {
                        Logger.d("获取分类成功:"+response.toString());
                        if (!DataUtil.isEmpty(response)) {
                            for (int i = 0; i < 4; i++) {//这里写固定的4，对应固定的四个分类
                                GoodsClassify goods = new GoodsClassify();
                                goods.setItemId(NO_CLASSIFY);
                                goodsClassifies.add(goods);
                            }
//                            goodsClassifies = response;
                            for (int j = 0; j < response.size(); j++) {
                                if (response.get(j).getName().equals("副食品")) {
                                    goodsClassifies.set(0,response.get(j));
                                    continue;
                                }
                                if (response.get(j).getName().equals("日用百货")) {
                                    goodsClassifies.set(1,response.get(j));
                                    continue;
                                }
                                if (response.get(j).getName().equals("其他")) {
                                    goodsClassifies.set(2,response.get(j));
                                    continue;
                                }
                                if (response.get(j).getName().equals("全部")) {
                                    goodsClassifies.set(3,response.get(j));
                                    continue;
                                }
                            }
//                            classifyAdapter = new ClassifyAdapter(activity, R.layout.classify_item, goodsClassifies);
//                            mClassifyLv.setAdapter(classifyAdapter);
//                            currClassifyId = goodsClassifies.get(0).getItemId();
                            getGoodsByClassifyId(currClassifyId);
//                            getHotGoods();
                        }
                    }

                    @Override
                    public void onError(int code, String errorMessage) {
                        super.onError(code, errorMessage);
                        Logger.e("获取分类失败:" + code + "," + errorMessage);
                    }

                    @Override
                    public Class<GoodsClassify> getType() {
                        return GoodsClassify.class;
                    }
                }
        );
    }

    private List<GoodsInfo> hotGoods = new ArrayList<>();

    /**
     * 获取热门商品
     */
//    private void getHotGoods() {
////        if (!DataUtil.isEmpty(hotGoods)) return;
//
//        int currPage = cacheData.containsKey(GOODS_ALL) ?
//                cacheData.get(GOODS_ALL).getPageDto().getPage() : Consts.DEFAULT_PAGE;
//        if (cacheData.containsKey(GOODS_ALL)) {
//            final Page oldPage = cacheData.get(GOODS_ALL).getPageDto();
//
//            if (currPage >= oldPage.getTotalPage()) {
//                finishRefreshOrLoadMore();
//                Utils.showToast(activity, Consts.DEFAULT_NO_DATA_HINT);
//                return;
//            }
//            currPage = oldPage.getPage() + 1;
//        }
//        ActionHelp.qrySellBestGoods(activity, currPage, Consts.PAGE_SIZE,
//                new ObjectCallback<GoodsPage>() {
//                    @Override
//                    public void onSuccess(GoodsPage response) {
//                        if (!DataUtil.isEmpty(response.getGoodsList())) {
//                            Logger.d("获取大家都在买成功:");
//                            hotGoods = response.getGoodsList();
////                            contentAdapter.replaceAll(hotGoods);
////                            mContentGv.setAdapter(new GoodsAdapter(activity, R.layout.hot_goods_item, hotGoods));
//                            finishRefreshOrLoadMore();
//                            final boolean hasFirst = !cacheData.containsKey(GOODS_ALL);
//                            currClassifyId = GOODS_ALL;
//                            if (null != response && !DataUtil.isEmpty(hotGoods)) {
//                                updateCacheData(currClassifyId, response);
//                                if (hasFirst) {
//                                    multipleStatusView.showContent();
//                                }
//                            } else {
//                                if (hasFirst) {
//                                    multipleStatusView.showEmpty();
//                                }
//                            }
//                        }
//                    }
//
//                    @Override
//                    public void onError(int code, String errorMessage) {
//                        super.onError(code, errorMessage);
//                        Logger.e("获取大家都在买失败:" + code + "," + errorMessage);
//                        finishRefreshOrLoadMore();
//                        if (!cacheData.containsKey(GOODS_ALL)) {
//                            if (null == multipleStatusView){
//                               multipleStatusView = (MultipleStatusView) findViewById(R.id.goods_home_multiple_status_view);
//                            }
//                            multipleStatusView.showError();
//                        }
//                    }
//
//                    @Override
//                    public Class<GoodsPage> getType() {
//                        return GoodsPage.class;
//                    }
//                }
//        );
//    }

    private HashMap<Long, GoodsPage> cacheData = new HashMap<>();

    private void getGoodsByClassifyId(final long classifyId) {
//        int currPage = cacheData.containsKey(classifyId) ?
//                cacheData.get(classifyId).getPageDto().getPage() : Consts.DEFAULT_PAGE;
//
//        if (cacheData.containsKey(classifyId)) {
//            final Page oldPage = cacheData.get(classifyId).getPageDto();
//            if (currPage >= oldPage.getTotalPage()) {
//                finishRefreshOrLoadMore();
//                Utils.showToast(activity, Consts.DEFAULT_NO_DATA_HINT);
//                return;
//            }
//            currPage = oldPage.getPage() + 1;
//        }

        ActionHelp.qryGoodsByItemId(activity, "30653916257587200",
                new ListCallback<GoodsInfo>() {
                    @Override
                    public void onSuccess(List<GoodsInfo> response) {
//                        finishRefreshOrLoadMore();
//                        final boolean hasFirst = !cacheData.containsKey(classifyId);
//                        if (null != response && !DataUtil.isEmpty(response.getGoodsList())) {
//                            updateCacheData(classifyId, response);
//                            if (hasFirst) {
//                                multipleStatusView.showContent();
//                            }
//                        } else {
//                            if (hasFirst) {
//                                multipleStatusView.showEmpty();
//                            }
//                        }
                        Logger.d("获取商品列表成功:" + response.toString());
                    }

                    @Override
                    public void onError(int code, String errorMessage) {
                        super.onError(code, errorMessage);
                        finishRefreshOrLoadMore();
                        Logger.e("获取商品列表失败:" + code + "," + errorMessage);
                        if (!cacheData.containsKey(classifyId) && multipleStatusView != null) {
                            multipleStatusView.showError();
                        }
                    }

                    @Override
                    public Class<GoodsInfo> getType() {
                        return GoodsInfo.class;
                    }
                }
        );
    }

//    private void updateCacheData(long classifyId, GoodsPage goodsPage) {
//        try {
//            if (cacheData.containsKey(classifyId)) {
//                cacheData.get(classifyId).getGoodsList().addAll(goodsPage.getGoodsList());
//                cacheData.get(classifyId).getPageDto().setPage(goodsPage.getPageDto().getPage());
//            } else {
//                cacheData.put(classifyId, goodsPage);
//            }
//            refreshAdapter(classifyId);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    private void refreshAdapter(long classifyId) {
//        if (classifyId==-100){
//
//        }else{
//
//        }
        multipleStatusView.showContent();
        contentAdapter.replaceAll(cacheData.get(classifyId).getGoodsList());
    }

    private View.OnClickListener onRetryClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            initLoadingView();
        }
    };

    @Override
    public void fillBannerItem(BGABanner banner, ImageView itemView, EBannerInfo model, int position) {
        Picasso.with(GoodsHomeActivity.this)
                .load(model.getPicUrl())
                .into(itemView);
    }

    @Override
    public void onBannerItemClick(BGABanner banner, ImageView itemView, EBannerInfo model, int position) {
        // type 类型 int  1为单个商品  2 为多个商品
        switch (model.getType()) {
            case 1:
                bannerGoodsInfo = new GoodsInfo();
                bannerGoodsInfo.setCoverUrl(model.getPicUrl());
                getDetailsInfo(Long.parseLong(model.getContent()));
                break;
            case 2:
                Intent intent = new Intent(GoodsHomeActivity.this, BannerListActivity.class);
                intent.putExtra(Consts.GOODS_BASE_URL_TO_WAP, model.getBannerUrl());
                intent.putExtra(Consts.GOODS_ID_TO_WAP, model.getContent());
                intent.putExtra(Consts.WAP_FROM_TYPE, model.getType());
                startActivity(intent);
                break;
            default:
                break;
        }
    }


    private void getDetailsInfo(final long goodsId) {
        ActionHelp.qryGoodsBase(activity, goodsId,
                new ObjectCallback<GoodsDetail>() {
                    @Override
                    public String filter(String json) {
                        return super.filter(json);
                    }

                    @Override
                    public void onSuccess(GoodsDetail response) {
                        if (null != response) {
                            bannerGoodsInfo.setBaseUrl(response.baseUrl);
                            bannerGoodsInfo.setActivityPrice(response.activityPrice);
                            bannerGoodsInfo.setDetailUrl(response.detailUrl);
                            bannerGoodsInfo.setGoodsId(response.goodsId);
                            bannerGoodsInfo.setGoodsType(response.goodsType);
                            bannerGoodsInfo.setMarketPrice(response.marketPrice);
                            bannerGoodsInfo.setSaleNum(response.saleNum);
                            bannerGoodsInfo.setSalePrice(response.salePrice);
                            bannerGoodsInfo.setTitle(response.title);
//                            GoodsDetailsActivity.start(activity, bannerGoodsInfo);
                        } else {
                            Logger.d("获取商品详情解析????????");
                        }
                    }

                    @Override
                    public Class<GoodsDetail> getType() {
                        return GoodsDetail.class;
                    }

                    @Override
                    public void onError(int code, String errorMessage) {
                        super.onError(code, errorMessage);
                        Logger.e("获取商品详情失败:" + code + "," + errorMessage);
                    }
                }
        );
    }

//    /**
//     * 分类item点击事件
//     */
//    private final class ClassifyItemClick implements AdapterView.OnItemClickListener {
//        @Override
//        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//            hasSearch = false;
//            classifyAdapter.setSelectedItem(position);
//            currClassifyId = goodsClassifies.get(position).getItemId();
//            if (cacheData.containsKey(currClassifyId)) {
//                refreshAdapter(currClassifyId);
//            } else {
//                getGoodsByClassifyId(currClassifyId);
//            }
//        }
//    }

    /**
     * 内容item点击事件
     */
    private final class ContentItemClick implements AdapterView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//            if (hasSearch) {
//                if (!DataUtil.isEmpty(searchResult) && position < searchResult.size()) {
//                    GoodsDetailsActivity.start(activity, searchResult.get(position));
//                }
//                return;
//            }
            try {
                final GoodsInfo goodsInfo = cacheData.get(currClassifyId).getGoodsList().get(position);
//                GoodsDetailsActivity.start(activity, goodsInfo);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

//    /**
//     * 热门商品item点击事件
//     */
//    private final class HotItemClick implements AdapterView.OnItemClickListener {
//        @Override
//        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//            final GoodsInfo goodsInfo = hotGoods.get(position);
//            GoodsDetailsActivity.start(activity, goodsInfo);
//        }
//    }


    private void getBanner() {
        ActionHelp.qryB2CBanners(activity, 1, 4, new ListCallback<EBannerInfo>() {
            @Override
            public void onSuccess(List<EBannerInfo> response) {
                banners.clear();
                if (!DataUtil.isEmpty(response)) {
                    banners.addAll(response);
                    BgaBanner.setData(banners, null);
                }
            }

            @Override
            public void onError(int code, String errorMessage) {
                super.onError(code, errorMessage);
                Logger.e("获取banner失败,code:" + code + ",message:" + errorMessage);
            }

            @Override
            public Class<EBannerInfo> getType() {
                return EBannerInfo.class;
            }
        });
    }


//    private List<GoodsInfo> searchResult;

//    private void searchGoods() {
//        final String searchStr = mSearch.getText().toString().trim();
//        if (TextUtils.isEmpty(searchStr)) {
//            Utils.showToast(activity, "请输入商品名称");
//            return;
//        }
//        ActionHelp.qryAllEpGoods(activity, 1, 200, searchStr, new ObjectCallback<GoodsPage>() {
//                    @Override
//                    public void onSuccess(GoodsPage response) {
//                        if (null != response && !DataUtil.isEmpty(response.getGoodsList())) {
//                            multipleStatusView.showContent();
//                            searchResult = response.getGoodsList();
//                            contentAdapter.replaceAll(searchResult);
//                        } else {
//                            multipleStatusView.showEmpty();
//                            Utils.showToast(activity, "没搜索到商品");
//                        }
//                    }
//
//                    @Override
//                    public void onError(int code, String errorMessage) {
//                        super.onError(code, errorMessage);
//                        Logger.e("搜索失败:" + errorMessage);
//                        multipleStatusView.showEmpty();
//                        Utils.showToast(activity, "搜索失败");
//                    }
//
//                    @Override
//                    public Class<GoodsPage> getType() {
//                        return GoodsPage.class;
//                    }
//                }
//        );
//    }

    // Header View
    private ProgressBar progressBar;
    private TextView textView;
    private ImageView imageView;
    // Footer View
    private ProgressBar footerProgressBar;
    private TextView footerTextView;
    private ImageView footerImageView;

    private View createHeaderView() {//设置头布局
        View headerView = LayoutInflater.from(mRefreshLayout.getContext()).inflate(R.layout.layout_head, null);
        progressBar = (ProgressBar) headerView.findViewById(R.id.pb_view);
        textView = (TextView) headerView.findViewById(R.id.text_view);
        textView.setText("下拉刷新");
        imageView = (ImageView) headerView.findViewById(R.id.image_view);
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageResource(R.mipmap.xrefreshview_arrow);
        progressBar.setVisibility(View.GONE);
        return headerView;
    }

    private View createFooterView() {//设置脚布局
        View footerView = LayoutInflater.from(mRefreshLayout.getContext()).inflate(R.layout.layout_footer, null);
        footerProgressBar = (ProgressBar) footerView.findViewById(R.id.footer_pb_view);
        footerImageView = (ImageView) footerView.findViewById(R.id.footer_image_view);
        footerTextView = (TextView) footerView.findViewById(R.id.footer_text_view);
        footerProgressBar.setVisibility(View.GONE);
        footerImageView.setVisibility(View.VISIBLE);
        footerImageView.setImageResource(R.mipmap.xrefreshview_arrow);
        footerTextView.setText("上拉加载更多...");
        return footerView;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
